package com.nofx.mydemo.publisher;

import com.nofx.mydemo.event.CustomSpringEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

/**
 * 自定义SpringEvent发布器
 * @author yyc-01407250
 * @date 2021年05月11日 13:56
 */
@Slf4j
@Component
public class CustomSpringEventPublisher {

    private final ApplicationEventPublisher applicationEventPublisher;

    public CustomSpringEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public void publishCustomEvent(final String message){
        log.info("Publishing custom event");
        CustomSpringEvent customSpringEvent = new CustomSpringEvent(this,message);
        applicationEventPublisher.publishEvent(customSpringEvent);
    }
}
